package weaver.formmode.customjavacode.modeexpand;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCode;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.common.Tools;
import weaver.soa.workflow.request.RequestInfo;
import weaver.system.code.CodeBuild;
import weaver.workflow.webservices.*;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 智能布署 智能布署任务清单
 * 批量发送任务 ：创建任务接收流程
 * 疑问：多个创建人的情况
 */
public class TaskCreateExpand extends AbstractModeExpandJavaCode {
    public String billids = "";
    public String workflowId = "298";//正式环境需要替换
    private final Logger logger = LoggerFactory.getLogger(TaskCreateExpand.class);
    String formmodeid = "77";//正式环境需要替换

    public String workflowTable = "formtable_main_365";

    String formmodeidTszs = "125";//正式环境需要替换 (特殊指数)



    private User user; //登陆用户


    private void createTask(RecordSet rs) {

        //多个模板id、任务标题rwbt、酒店代码jddm、酒店名称jdmc、任务类型rwlx、致胜指数zszs、风险系数fxxs、
        // cjgwry创建人id、sjgwry收件人id、csgwry抄送人id、任务互动类型rwhdlx、任务到期时间rwdqsj、任务内容rwnr
        String dymb = rs.getString("dymb");
        String rwbt = rs.getString("rwbt");
        String jddm = rs.getString("jddm");
        String jdmc = rs.getString("jdmc");
        String rwlx = rs.getString("rwlx");
        String zszs = rs.getString("zszs");
        String cjgwry = rs.getString("cjgwry");
        String sjgwry = rs.getString("sjgwry");
        String csgwry = rs.getString("csgwry");
        String rwhdlx = rs.getString("rwhdlx");
        String rwdqsj = rs.getString("rwdqsj"); //整数,创建时间+该字段=真实到期时间
        String rwnr = rs.getString("rwnr");
        String xscfj = Util.null2String(rs.getString("xscfj")); //是否上传附件
        String id = rs.getString("id");

        String cjgw = rs.getString("cjgw");  //创建岗位
        String sjgw = rs.getString("sjgw");  //收件岗位
        String csgw = rs.getString("csgw");  //抄送岗位

        String racisz = rs.getString("racisz");  //raci设置
        String rwbq = rs.getString("rwbq");  //任务标签
        String gfxzsxx = rs.getString("gfxzsxx");  //高风险指数信息id
        String zysx = rs.getString("zysx");  //
        String qrsx = rs.getString("qrsx");  //
        String rwscfs = rs.getString("rwscfs");  //

        String yrmonbr = rs.getString("yrmonbr");  //YR_MO_NBR (时间 YYYYmmDD)





        RecordSet selTaskTrueRs = new RecordSet();
        String selTaskTrue = "select * from uf_rwxfyfs where jddm = '"+ jddm +"' and yrmonbr ='"+yrmonbr + "' and zszs like '%"+zszs+"%'";
        selTaskTrueRs.executeQuery(selTaskTrue);
        // logger.info("TaskCreateExpand_znbszt=0_selTaskTrue:"+selTaskTrue);
        if (selTaskTrueRs.next()) {
            RecordSet updateSet = new RecordSet();
            String updateSql = "update uf_znbsqd set sfyfs = 0  where id = "+id;
            // logger.info("TaskCreateExpand_znbszt=1_selTaskTrue:"+updateSql);
            updateSet.executeUpdate(updateSql);
            return;
        }



        //角色组的管理员名单
        String adminname = "";
        String rolename = "";
        if (!"".equals(sjgwry)){
            //任务接收人的管理员
            RecordSet roleGroupSet = new RecordSet();
            String roleGroupSql = "select adminname,id from uf_rolegroup where LOCATE("+sjgwry+", lineuser) > 0;";
            // logger.info("TaskCreateExpand_sjgwry_roleGroupSql:"+ roleGroupSql);
            roleGroupSet.executeQuery(roleGroupSql);
            if (roleGroupSet.next()){
                adminname = roleGroupSet.getString("adminname");
                rolename = roleGroupSet.getString("id");
            }
        }



        //获取待发明细表1数据
        RecordSet td1Rs = new RecordSet();
        td1Rs.executeQuery("select * from uf_znbsqd_dt1 where mainid = ?",id);
        // logger.info("TaskCreateExpand_td1Rs:"+td1Rs);

        //获取待发明细表2数据
        RecordSet td2Rs = new RecordSet();
        td2Rs.executeQuery("select * from uf_znbsqd_dt2 where mainid = ?",id);
        // logger.info("TaskCreateExpand_td2Rs:"+td2Rs);

        try {

            WorkflowService wfimp = new WorkflowServiceImpl();

            WorkflowRequestInfo workflowRequestInfo = new WorkflowRequestInfo();//工作流程请求信息

//		            workflowRequestInfo.setRequestId(String.valueOf(1918557));//流程请求ID-创建流程时自动产生
            workflowRequestInfo.setCanView(true);//显示
            workflowRequestInfo.setCanEdit(true);//可编辑
            workflowRequestInfo.setRequestName(rwbt);//请求标题
            workflowRequestInfo.setRequestLevel("0");//请求重要级别
            workflowRequestInfo.setCreatorId(cjgwry);//流程创建人

            WorkflowBaseInfo workflowBaseInfo = new WorkflowBaseInfo();//工作流信息
            workflowBaseInfo.setWorkflowId(workflowId);//流程ID
            workflowBaseInfo.setWorkflowName("任务接收");//流程名称
//		workflowBaseInfo.setWorkflowTypeId("1951");//流程类型id
            workflowBaseInfo.setWorkflowTypeName("webservice-test");//流程类型名称
            workflowRequestInfo.setWorkflowBaseInfo(workflowBaseInfo);//工作流信息

            /****************main table start*************/

            String codeStrInner = "";


            Map<String, String> map = new HashMap<>();
            map.put("actionid",codeStrInner);//任务编号
            map.put("hdbt",rwbt);//任务标题
            map.put("hdcjr",cjgwry);//任务创建人
            map.put("rwzt","0");//任务状态
            String createTime = Tools.getDateTime(new Date());
            map.put("hdcjrq",createTime);//任务创建日:当前日期
            map.put("hddqr",rwdqsj);//任务到期日
            map.put("hdlx",rwlx);//任务类型:大区任务　酒店任务
            map.put("rwhdlx",rwhdlx);//任务互动类型:酒店现场　线上讨论
            map.put("wcssftjfj",xscfj);//需上传附件
            map.put("szfqgly",adminname);//管理员名单
            map.put("jddm",jddm);//酒店代码
            map.put("jdmc",jdmc);//酒店名称
            map.put("zszs",zszs);//致胜指数
            map.put("jsmc",rolename);//管理员角色名称
            map.put("hdnr",rwnr);//任务内容
            map.put("rwjsr",sjgwry);//任务接收人
            map.put("csry",csgwry);//任务抄送人
//          map.put("bq",rwbq);//任务标签
            map.put("rwbq",rwbq);//任务标签(新字段)
            map.put("zysx",zysx);//check框
            map.put("qrsx",qrsx);//check框
            map.put("rwscfs","1");//check框

            WorkflowMainTableInfo mainInfo = getMainInfo(map);

            workflowRequestInfo.setWorkflowMainTableInfo(mainInfo);
            /****************main table end*************/
            int counts1 = td1Rs.getCounts();
            int counts2 = td2Rs.getCounts();
            // logger.info("TaskCreateExpand_td1Rs.getCounts:"+counts1 +"_td2Rs.getCounts:"+counts2);
            if (td1Rs.getCounts()>0 || td2Rs.getCounts()>0){
                // logger.info("TaskCreateExpand_td1Rs.getCounts()>0 || td2Rs.getCounts()>0");

                /****************detail table start 流程明细表 开始 *************/
                WorkflowDetailTableInfo[] workflowDetailTableInfo = new WorkflowDetailTableInfo[3];//两个明细表
                detilWorkflower(td1Rs, td2Rs, workflowDetailTableInfo);
                workflowRequestInfo.setWorkflowDetailTableInfos(workflowDetailTableInfo);
            }



//            workflowRequestInfo.setWorkflowDetailTableInfos(null);

            String requestId = wfimp.doCreateWorkflowRequest(workflowRequestInfo, Integer.parseInt(cjgwry));
             logger.info("TaskCreateExpand-requestid:"+requestId);
            if (Util.getIntValue(requestId) > 0) {

                RecordSet codeStrInnerSet = new RecordSet();
                codeStrInnerSet.executeQuery("select actionid from "+workflowTable +" where requestId ="+requestId);
                if (codeStrInnerSet.next()) {
                    codeStrInner = codeStrInnerSet.getString("actionid");
                    // logger.info("TaskCreateExpand-actionid(codeStrInner):"+codeStrInner);
                }

                //修改任务清单表 关联流程id
                //touchpointbh任务编号、hdbt任务名称、jdmc酒店名称(英)、hdcjr任务创建人、hdrq任务创建日、rwjsr任务接收人、hddqr任务到期日、zszs致胜指数、zt状态
                RecordSet insertTaskSet = new RecordSet();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                createTime = dateFormat.format(new Date());

                if ("".equals(xscfj)){
                    xscfj = null;
                }
                if ("".equals(rwhdlx)){
                    rwhdlx = null;
                }

                String insertTaskSql = "insert into uf_rwtzeq(touchpointbh,hdbt,jddm,jdmc,hdcjr,hdrq,rwjsr,hddqr,zszs,zt,rwmc,formmodeid,hdlx,hdnr,wcssfxytjfj,jszglymd,csry,hdhdlx,jsmc,cjgw,sjgw,csgw,rwscfs,bq) " +
                        " values( '"+codeStrInner+"','"+rwbt+"','"+jddm+"','"+jdmc+"','"+cjgwry+"','"+createTime+"','"+sjgwry+"','"+rwdqsj+"','"+zszs+"',1,'"+requestId+"','"+formmodeid+"','"+rwlx+"','"+rwnr+"',"+xscfj+",'"+adminname+"','"+csgwry+"',"+rwhdlx+",'"+rolename+"','"+cjgw+"','"+sjgw+"','"+csgw+"',1,'"+rwbq+"')";
                 logger.info("TaskCreateExpand_insertTaskSql:"+insertTaskSql);
                insertTaskSet.executeUpdate(insertTaskSql);

                saveDetilRs(td1Rs, td2Rs, requestId, insertTaskSet,id);


                RecordSet updateSet = new RecordSet();
                String updateSql = "update uf_znbsqd set sfyfs = 0 , rwfssj = NOW() where id = ?";
                // logger.info("TaskCreateExpand_updateSql:"+updateSql);
                updateSet.executeUpdate(updateSql,id);

                //修改待发清单 酒店id+指数+YR MO NBR 一致的数据 状态为 已发送
                String updateDfSql = "update uf_znbsqd set sfyfs = 0  where jddm ='"+jddm +"' and zszs = '"+zszs +"' and yrmonbr='"+yrmonbr+"'";
                // logger.info("TaskCreateExpand_updateDfSql:"+updateDfSql);
                updateSet.executeUpdate(updateDfSql);


                String addTaskTrue= "insert into uf_rwxfyfs(jddm,yrmonbr,zszs,formmodeid,lcid,rwqdsjid) values( '"+jddm+"','"+yrmonbr+"','"+zszs+"',"+formmodeidTszs+",'"+requestId+"','"+id+"')";
                // logger.info("TaskCreatAction_addTaskTrue:"+addTaskTrue);
                insertTaskSet.executeUpdate(addTaskTrue);





                //创建成功，修改高风险指数表对应的 数据为已发送
                RecordSet zszsRs = new RecordSet();
                //酒店id、指数id、rac设置(包含：多个则为特殊指数)、qrzt确认状态为已确认1
//                String zszsSql = "select * from uf_gfxzsxxgl where qrzt = 1 and INNCODE = "+ jddm +" and MTRX = "+zszs+" and racisz in("+ racisz+")";
                String zszsSql = "select * from uf_gfxzsxxgl where  id in("+ gfxzsxx+")";
                // logger.info("TaskCreateExpand_zszsSql:"+zszsSql);
                zszsRs.executeQuery(zszsSql);
                while (zszsRs.next()){
                    //每一期仅存在一条已确认的对应数据
                    String gfxzsId = zszsRs.getString("id"); //
                    String raci = zszsRs.getString("racisz"); //如果raci设置中存在多条数据，则表示为特殊指数(不包含特殊情况)
                    //修改状态为已发送,不再生成新的待发清单
                    String sfyfsUpdate = " update uf_gfxzsxxgl  set sfyfs = 0  where id = "+gfxzsId;
                    zszsRs.executeUpdate(sfyfsUpdate);
                    // logger.info("TaskCreateExpand_sfyfsUpdate:"+sfyfsUpdate);

                    //特殊指数逻辑
//                    String tszsSql = "select * from uf_tszszsdyb where id = "+zszs;
//                    zszsRs.executeQuery(tszsSql);
//                    //只有为特殊指数时，才会 删除生成的多条待发
//                    if (!"".equals(raci)){
//                        List<String> raciList = Arrays.asList(raci.split(","));
//                        if (raciList.size()>1) {
//                            //只有raci设置 存的数据大于1，才表示生成了多条待发清单
//                            raciList.remove(racisz); //移除本次
//                            for (String raciId : raciList) {
//                                //删除 racisz为本次数据 + jddm  + zszs
//                                zszsRs.executeUpdate("delete from uf_znbsqd where racisz = ? and jddm = ? and zszs = ?",raciId,jddm,zszs);
//                            }
//                        }
//                    }
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void saveDetilRs(RecordSet td1Rs, RecordSet td2Rs, String requestId, RecordSet insertTaskSet, String id) {
        //获取待发明细表1数据
        td1Rs.executeQuery("select * from uf_znbsqd_dt1 where mainid = ?",id);

        //获取待发明细表2数据
        td2Rs.executeQuery("select * from uf_znbsqd_dt2 where mainid = ?",id);

        if (td1Rs.getCounts()>0 || td2Rs.getCounts()>0){
            RecordSet recordSet = new RecordSet();
            recordSet.executeQuery("select id from uf_rwtzeq where rwmc = ?", requestId);
            String mainid = "";
            if (recordSet.next()) mainid = recordSet.getString("id");
            // logger.info("TaskCreateExpand_td_mainid:"+mainid);
            if (td1Rs.getCounts()>0) {
                // logger.info("TaskCreateExpand_td1Rs.getCounts()>0");
                //添加明细表1
                while (td1Rs.next()) {
                    String yrmtnbr = td1Rs.getString("yrmtnbr");
                    String zsmc = td1Rs.getString("zsmc");
                    String ndjg = formatDecimalValue(td1Rs.getString("ndjg"));
                    String ndmb = formatDecimalValue(td1Rs.getString("ndmb"));
                    String ydjg = formatDecimalValue(td1Rs.getString("ydjg"));
                    String ydmb = formatDecimalValue(td1Rs.getString("ydmb"));

                    String insertTaskTd1Sql = "insert into uf_rwtzeq_dt4(yrmonbr,zszs,ndjg,ndmb,ydjg,ydmb,mainid) " +
                            " values( '"+yrmtnbr+"','"+zsmc+"',"+ndjg+","+ndmb+","+ydjg+","+ydmb+","+mainid+")";
                    // logger.info("TaskCreateExpand_insertTd1TaskSql:"+ insertTaskTd1Sql);
                    insertTaskSet.executeUpdate(insertTaskTd1Sql);
                }
            }


            //添加明细表2
            if (td2Rs.getCounts()>0) {
                // logger.info("TaskCreateExpand_td2Rs.getCounts()>0");
                while (td2Rs.next()) {
                    String yrmtnbr = td2Rs.getString("yrmtnbr");
                    String csmc = td2Rs.getString("csmc");
                    String ndjg = formatDecimalValue(td2Rs.getString("ndjg"));
                    String ndmb = formatDecimalValue(td2Rs.getString("ndmb"));
                    String ydjg = formatDecimalValue(td2Rs.getString("ydjg"));
                    String ydmb = formatDecimalValue(td2Rs.getString("ydmb"));
                    String insertTaskTd2Sql = "insert into uf_rwtzeq_dt5(yrmonbr,csmc,ndjg,ndmb,ydjg,ydmb,mainid) " +
                            " values( '" + yrmtnbr + "','" + csmc + "'," + ndjg + "," + ndmb + "," + ydjg + "," + ydmb + ","+mainid+")";
                    // logger.info("TaskCreateExpand_insertTd2TaskSql:" + insertTaskTd2Sql);
                    insertTaskSet.executeUpdate(insertTaskTd2Sql);
                }
            }

        }
    }


    // 处理空值的方法
    private String formatDecimalValue(String value) {
        return (value == null || value.trim().isEmpty()) ? "NULL" : value;
    }



    private void detilWorkflower(RecordSet td1Rs, RecordSet td2Rs, WorkflowDetailTableInfo[] workflowDetailTableInfo) {
//        WorkflowRequestTableRecord[] workflowRequestTableRecord;
//        WorkflowRequestTableField[] WorkflowRequestTableField;
        if (td1Rs.getCounts()>0) {
            // logger.info("TaskCreateExpand_td1_start_____");
            /**********第一张明细表开始**********/
            WorkflowRequestTableRecord[]  workflowRequestTableRecord = new WorkflowRequestTableRecord[td1Rs.getCounts()];//数据条数（记录）
            WorkflowRequestTableField[]  WorkflowRequestTableField = null;
            int td1Num = 0;
            while (td1Rs.next()) {

                WorkflowRequestTableField = new WorkflowRequestTableField[6];//每行6个字段


                String td1id = td1Rs.getString("id");
                String yrmtnbr = td1Rs.getString("yrmtnbr");
                String zsmc = td1Rs.getString("zsmc");
                String ndjg = td1Rs.getString("ndjg");
                String ndmb = td1Rs.getString("ndmb");
                String ydjg = td1Rs.getString("ydjg");
                String ydmb = td1Rs.getString("ydmb");

                // logger.info("TaskCreateExpand_td1: "+td1id+"_yrmtnbr: "+yrmtnbr+" _zsmc: "+zsmc+"_ndjg:"+ndjg +"_ydjg:"+ydjg +"_ydmb:"+ydmb);
                /****第一行开始****/
                WorkflowRequestTableField[0] = new WorkflowRequestTableField();
                WorkflowRequestTableField[0].setFieldName("yrmonbr");//td1 YR_MO_NBR
                WorkflowRequestTableField[0].setFieldValue(yrmtnbr);
                WorkflowRequestTableField[0].setView(true);
                WorkflowRequestTableField[0].setEdit(true);

                WorkflowRequestTableField[1] = new WorkflowRequestTableField();
                WorkflowRequestTableField[1].setFieldName("zszs");//td1 致胜指数 zsmc
                WorkflowRequestTableField[1].setFieldValue(zsmc);
                WorkflowRequestTableField[1].setView(true);
                WorkflowRequestTableField[1].setEdit(true);

                WorkflowRequestTableField[2] = new WorkflowRequestTableField();
                WorkflowRequestTableField[2].setFieldName("ndjg");//年度结果  ndjg
                WorkflowRequestTableField[2].setFieldValue(ndjg);
                WorkflowRequestTableField[2].setView(true);
                WorkflowRequestTableField[2].setEdit(true);

                WorkflowRequestTableField[3] = new WorkflowRequestTableField();
                WorkflowRequestTableField[3].setFieldName("ndmb");//年度目标
                WorkflowRequestTableField[3].setFieldValue(ndmb);
                WorkflowRequestTableField[3].setView(true);
                WorkflowRequestTableField[3].setEdit(true);

                WorkflowRequestTableField[4] = new WorkflowRequestTableField();
                WorkflowRequestTableField[4].setFieldName("ydjg");//月度结果
                WorkflowRequestTableField[4].setFieldValue(ydjg);
                WorkflowRequestTableField[4].setView(true);
                WorkflowRequestTableField[4].setEdit(true);

                WorkflowRequestTableField[5] = new WorkflowRequestTableField();
                WorkflowRequestTableField[5].setFieldName("ydmb");//月度目标
                WorkflowRequestTableField[5].setFieldValue(ydmb);
                WorkflowRequestTableField[5].setView(true);
                WorkflowRequestTableField[5].setEdit(true);

                workflowRequestTableRecord[td1Num] = new WorkflowRequestTableRecord();
                workflowRequestTableRecord[td1Num].setWorkflowRequestTableFields(WorkflowRequestTableField);

                td1Num = td1Num+1;
                /****第一行结束****/
            }
            int rownum = 1;

            workflowDetailTableInfo[rownum] =new WorkflowDetailTableInfo();
            workflowDetailTableInfo[rownum].setWorkflowRequestTableRecords(workflowRequestTableRecord);
            /**********第一张明细表结束**********/
        }

        if (td2Rs.getCounts()>0) {
            // logger.info("TaskCreateExpand_td2_start_____");
            /**********第一张明细表开始**********/
            WorkflowRequestTableRecord[]   workflowRequestTableRecord = new WorkflowRequestTableRecord[td2Rs.getCounts()];//数据条数（记录）
            WorkflowRequestTableField[] WorkflowRequestTableField = null;
            int td1Num = 0;
            while (td2Rs.next()) {
                WorkflowRequestTableField = new WorkflowRequestTableField[6];//每行6个字段

                String td2id = td2Rs.getString("id");
                String yrmtnbr = td2Rs.getString("yrmtnbr");
                String csmc = td2Rs.getString("csmc");
                String ndjg = td2Rs.getString("ndjg");
                String ndmb = td2Rs.getString("ndmb");
                String ydjg = td2Rs.getString("ydjg");
                String ydmb = td2Rs.getString("ydmb");
                // logger.info("TaskCreateExpand_td2: "+td2id+"_yrmtnbr: "+yrmtnbr+" _csmc: "+csmc+"_ndjg:"+ndjg +"_ndmb:"+ndmb +"_ydjg:"+ydjg +"_ydmb:"+ydmb);

                /****第一行开始****/
                WorkflowRequestTableField[0] = new WorkflowRequestTableField();
                WorkflowRequestTableField[0].setFieldName("yrmonbr");//td2 YR_MO_NBR
                WorkflowRequestTableField[0].setFieldValue(yrmtnbr);
                WorkflowRequestTableField[0].setView(true);
                WorkflowRequestTableField[0].setEdit(true);

                WorkflowRequestTableField[1] = new WorkflowRequestTableField();
                WorkflowRequestTableField[1].setFieldName("csmc");//td2 参数名称 csmc
                WorkflowRequestTableField[1].setFieldValue(csmc);
                WorkflowRequestTableField[1].setView(true);
                WorkflowRequestTableField[1].setEdit(true);

                WorkflowRequestTableField[2] = new WorkflowRequestTableField();
                WorkflowRequestTableField[2].setFieldName("ndjg");//年度结果  ndjg
                WorkflowRequestTableField[2].setFieldValue(ndjg);
                WorkflowRequestTableField[2].setView(true);
                WorkflowRequestTableField[2].setEdit(true);

                WorkflowRequestTableField[3] = new WorkflowRequestTableField();
                WorkflowRequestTableField[3].setFieldName("ndmb");//年度目标
                WorkflowRequestTableField[3].setFieldValue(ndmb);
                WorkflowRequestTableField[3].setView(true);
                WorkflowRequestTableField[3].setEdit(true);

                WorkflowRequestTableField[4] = new WorkflowRequestTableField();
                WorkflowRequestTableField[4].setFieldName("ydjg");//月度结果
                WorkflowRequestTableField[4].setFieldValue(ydjg);
                WorkflowRequestTableField[4].setView(true);
                WorkflowRequestTableField[4].setEdit(true);

                WorkflowRequestTableField[5] = new WorkflowRequestTableField();
                WorkflowRequestTableField[5].setFieldName("ydmb");//月度目标
                WorkflowRequestTableField[5].setFieldValue(ydmb);
                WorkflowRequestTableField[5].setView(true);
                WorkflowRequestTableField[5].setEdit(true);

                workflowRequestTableRecord[td1Num] = new WorkflowRequestTableRecord();
                workflowRequestTableRecord[td1Num].setWorkflowRequestTableFields(WorkflowRequestTableField);

                td1Num = td1Num+1;
                /****第一行结束****/
            }
            int rownum = 2;
            workflowDetailTableInfo[rownum] =new WorkflowDetailTableInfo();
            workflowDetailTableInfo[rownum].setWorkflowRequestTableRecords(workflowRequestTableRecord);
            /**********第一张明细表结束**********/
        }
    }

    @Override
    public void doModeExpand(Map<String, Object> param) {
//        HashMap<String, String> map = new HashMap<>();
        // logger.info("TaskCreateExpand_start_____");
        RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
//        RequestManager requestManager = requestInfo.getRequestManager();
//        user = requestManager.getUser();
        billids = requestInfo.getRequestid();
         logger.info("TaskCreateExpand_getBillid:"+billids);
        if (!"".equals(billids)){
            // logger.info("TaskCreateExpand_getBillid is not null");
            RecordSet rs = new RecordSet();
            //执行查询语句，查询数据 ,查询智能布署清单表的未发送数据
            // 添加逻辑(1：状态为：未发送sfyfs 状态满足znbszt  2：发送成功后创建台账数据并关联requestid 3：台账添加后修改该条发送任务的状态为已发送 )
            String rsSql = "select * from uf_znbsqd where sfyfs = 1 and znbszt = 0 and id in("+billids+")";
            rs.executeQuery(rsSql);
            // logger.info("TaskCreateExpand_rsSql:"+rsSql);
            while (rs.next()) {
                // logger.info("TaskCreateExpand_createTask___");
                //执行创建流程方法
                createTask(rs);
            }
        }

    }


    /**
     * 组装主表数据
     * @param map
     * @return
     */
    public WorkflowMainTableInfo getMainInfo(Map<String, String> map) {
        // logger.writeLogInfo( this.getClass().getName(), JobName + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>create main data start>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        WorkflowMainTableInfo workflowMainTableInfo = new WorkflowMainTableInfo();//定义一个主表对象
        WorkflowRequestTableRecord[] workflowRequestTableRecord = new WorkflowRequestTableRecord[1];//创建多少行主表数据
        List<WorkflowRequestTableField> main_dwrs = new ArrayList<WorkflowRequestTableField>();//一行
        WorkflowRequestTableField main_det_wrti = null;
        for (String s : map.keySet()) {
            main_det_wrti = new WorkflowRequestTableField();//一个字段
            String value = map.get(s);
            main_det_wrti.setFieldName(s);
            main_det_wrti.setFieldValue(value);
            main_det_wrti.setView(true);
            main_det_wrti.setEdit(true);
            main_dwrs.add(main_det_wrti);
        }
        WorkflowRequestTableField[] workflowRequestTableFields = new WorkflowRequestTableField[main_dwrs.size()];
        for (int i = 0; i < main_dwrs.size(); i++) {
            workflowRequestTableFields[i] = main_dwrs.get(i);
        }
        workflowRequestTableRecord[0] = new WorkflowRequestTableRecord();
        workflowRequestTableRecord[0].setWorkflowRequestTableFields(workflowRequestTableFields);
        workflowMainTableInfo.setRequestRecords(workflowRequestTableRecord);
        // logger.writeLogInfo( this.getClass().getName(), JobName + "create main data end>>>>>>>>>>>>>>>>>>>>>>>>>" + workflowMainTableInfo);
        return workflowMainTableInfo;
    }




}
